package com.baizhi.controller;

import com.baizhi.annotation.LogAnnotation;
import com.baizhi.entity.Cmfzmenu;
import com.baizhi.service.CmfzmenuService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("menu")
public class CmfzmenuController {
    @Autowired
    private CmfzmenuService cmfzmenuService;
    /*@RequestMapping("selectAll")
    @ResponseBody
    @LogAnnotation(content = "查询菜单",type = "查询")
    public Map selectAll(){
        Map map = new HashMap();
        List<Cmfzmenu> cmfzmenus = cmfzmenuService.selectAll();
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        System.out.println("列表："+cmfzmenus);
        map.put("code",0);
        map.put("msg","");
        map.put("count",0);
        map.put("data",cmfzmenus);
        return map;
    }*/
    /*测试代码式授权*/
    @RequestMapping("selectAll")
    @ResponseBody
    @LogAnnotation(content = "查询菜单",type = "查询")
    public Map selectAll(){
        /*
        * 代码式授权
        * 验证 当前用户如果有select：menu的权限才能够查询到数据
        * */
        /*
        * 1.获取subject
        * */
        Subject subject = SecurityUtils.getSubject();
        /*
        * 2.代码式授权
        * */
        if (subject.isPermitted("select:menu")){
            Map map = new HashMap();
            List<Cmfzmenu> cmfzmenus = cmfzmenuService.selectAll();
            System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            System.out.println("列表："+cmfzmenus);
            map.put("code",0);
            map.put("msg","");
            map.put("count",0);
            map.put("data",cmfzmenus);
            return map;
        }else {
            return null;
        }
    }
}
